package com.ruoyi.quartz.task;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.google.gson.Gson;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 天气接口信息获取定时任务调度
 * 
 * @author linziheng
 */
@Component("weatherTask")
public class WeatherTask
{
    @Autowired
    private RedisCache redisCache;

    public void weatherParams() {
        String res = HttpUtils.sendGet("https://restapi.amap.com/v3/weather/weatherInfo?city=110101&key=d9bdcd2b88ca8efc8a495de992ef33b4");
        JSONObject jsonObject = JSON.parseObject(res);
        if (jsonObject.get("infocode").equals("10000")) {
            //获取成功
            JSONArray jsonArray = jsonObject.getJSONArray("lives");
            // 创建Gson对象
            // 将JSON字符串转换为User对象
            redisCache.setCacheObject("weatherInfo", jsonArray.get(0).toString());
        }
    }
}
